package com.aier.admin_new.action;

import java.io.File;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.common.ImageUtil;
import com.aier.school.entity.School;
import com.aier.school.entity.SchoolGrade;
import com.aier.school.entity.SchoolInfoDetail;
import com.aier.school.entity.SchoolTeacher;
import com.aier.school.service.ISchoolService;
import com.aier.school.service.ISchoolTeacherService;
import com.aier.user.entity.User;
import com.aier.user.service.IUserService;

//学校管理员界面
@Scope("prototype")
@Component("schoolinfoNAction")
public class SchoolinfoNAction extends AdminNewBaseAction {
	private long uid;
	private int sid;
	private int s ;
	private String errorMessage;
	private School school;
	private SchoolInfoDetail  schoolInfoDetail;
	private User user;

	
	@Resource(name = "userService")
	private IUserService userService;
	@Resource(name = "schoolService")
	private ISchoolService schoolService;
	@Resource(name = "schoolTeacherService")
	private ISchoolTeacherService schoolTeacherService;
	
	@Override
	public String execute() throws Exception {		
		school = schoolService.searchSchoolBySid(sid);
		List<SchoolGrade> listG=schoolService.searchSchoolGradeList(sid);
		long gid = 0 ;
    	for(SchoolGrade sg:listG){
    		if(sg.getName().equals("园长")==true){
    			gid=sg.getGid();
    		}
    	}
    	
    	List<SchoolTeacher> list =schoolTeacherService.selectTeacher(sid, "", gid);
    	long luid = 0;
    	if(list.size()>0){
	    	for(  int i =0 ;i<list.size() ; i++){
	    		SchoolTeacher st=list.get(i);
	    		luid=st.getUid();
		    	 user =userService.getUserByUid(luid);
	    	}
    	}
		return super.execute();
	}
	 // 学校信息
    public String serachAvatar() {
    	school = schoolService.searchSchoolBySid(sid);
    	schoolInfoDetail=schoolService.searchSchoolInfoBySid(sid);    	
    	List<SchoolGrade> listG=schoolService.searchSchoolGradeList(sid);
    	long gid = 0 ;
    	for(SchoolGrade sg:listG){
    		if(sg.getName().equals("园长")==true){
    			gid=sg.getGid();
    		}
    	}
    	
    	List<SchoolTeacher> list =schoolTeacherService.selectTeacher(sid, "", gid);
    	long luid = 0;
    	if(list.size()>0){
	    	for(  int i =0 ;i<list.size() ; i++){
	    		SchoolTeacher st=list.get(i);
	    		luid=st.getUid();
		    	 user =userService.getUserByUid(luid);
	    	}
    	}
    	
    	if (null != school && schoolInfoDetail!=null) {
           s=1;
        }else{
           s=0;
        }
        return SUCCESS;
    }
	public long getUid() {
		return uid;
	}
	public void setUid(long uid) {
		this.uid = uid;
	}
	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public int getS() {
		return s;
	}
	public String getErrorMessage() {
		return errorMessage;
	}

	public School getSchool() {
		return school;
	}
	public SchoolInfoDetail getSchoolInfoDetail() {
		return schoolInfoDetail;
	}
	public User getUser() {
		return user;
	}
}
